package com.smartEdu.interceptors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import com.smartEdu.commons.LogCvt;
import com.smartEdu.exception.SystemException;
import com.smartEdu.exception.SystemInitException;

/**
 * 全局异常拦截器
 */
@Component
public class GlobalExceptionInterceptor implements HandlerExceptionResolver {

	@Override
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {
		
		if (ex instanceof SystemException) {
			LogCvt.error("系统异常：" + ((SystemException) ex).getMessage(), 
					((SystemException) ex).getCause());
		}
		if (ex instanceof SystemInitException) {
			LogCvt.error("系统异常：" + ((SystemException) ex).getMessage(), 
					((SystemException) ex).getCause());
			System.exit(1);
		}
		return new ModelAndView();
	}
	
}
